package com.zhenyi.fenda.interceptor;

import com.fenda.common.model.FdMaster;
import com.fenda.common.model.FdUser;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;
import com.utils.AuthUtils;

public class MasterInterceptor implements Interceptor {

	@Override
	public void intercept(Invocation inv) {
		Controller controller = inv.getController();
		if (AuthUtils.verify(controller)) {
			String userId = AuthUtils.getTokenUid(controller);
			FdUser user = FdUser.dao.findById(userId);
			FdMaster master = FdMaster.dao.findById(user.getId());
			if (master != null) {
				inv.invoke();
				return;
			} else {
				AuthUtils.logout(controller);
				controller.renderText("不是大师");
			}
		}
	}
}
